package com.mxpio.erp.common.equipment.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.jpa.policy.ResCodeGeneratorPolicy;
import com.mxpioframework.jpa.annotation.Generator;
import com.mxpioframework.jpa.policy.impl.UUIDPolicy;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.BaseEntity;
import com.mxpioframework.security.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * 保养任务对象 MB_ERP_EQUIPMENT_UPKEEP_TASK
 * 
 * @author Cheng
 * @date 2023-07-28
 */
@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "MB_ERP_EQUIPMENT_UPKEEP_TASK")
@Schema(description="保养任务")
public class EquipmentUpkeepTask extends BaseEntity {

private static final long serialVersionUID=1L;

    @Id
    @Generator(policy = UUIDPolicy.class)
    @Column(name = "ID_")
    @Schema(description = "主键")
    private String id;

    @Column(name = "ORDER_CODE_")
    @Schema(description = "工单编码")
    @Generator(policy = ResCodeGeneratorPolicy.class)
    private String orderCode;

    @Column(name = "TARGET_TYPE_")
    @Schema(description = "目标类型")
    @Dict(dicCode = "ERP_EQUIPMENT_TASK_TARGET_TYPE")
    private String targetType;

    @Column(name = "TARGET_ID_")
    @Schema(description = "目标ID")
    private String targetId;

    @Column(name = "TARGET_NAME_")
    @Schema(description = "目标名称")
    private String targetName;

    @Column(name = "TARGET_CODE_")
    @Schema(description = "目标编码")
    private String targetCode;

    @Column(name = "TARGET_SPEC_")
    @Schema(description = "设备型号")
    private String targetSpec;

    @Column(name = "POSITION_")
    @Schema(description = "具体位置")
    private String position;

    @Column(name = "ORDER_STATUS_")
    @Schema(description = "工单状态")
    @Dict(dicCode = "ERP_EQUIPMENT_UPKEEPTASK_STATUS")
    private Integer orderStatus;

    @Column(name = "CREATE_TYPE_")
    @Schema(description = "生成类型")
    private String createType;

    @Column(name = "PLAN_START_TIME_")
    @Schema(description = "计划开始时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date planStartTime;

    @Column(name = "PLAN_END_TIME_")
    @Schema(description = "计划结束时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date planEndTime;

    @Column(name = "RELEASE_TARGET_TYPE_")
    @Schema(description = "下达目标类型")
    @Dict(dicCode = "ERP_EQUIPMENT_RELEASE_TARGET_TYPE")
    private String releaseTargetType;

    @Column(name = "RELEASE_TARGET_ID_")
    @Schema(description = "下达目标")
    private String releaseTargetId;

    @Column(name = "RELEASE_TARGET_NAME_")
    @Schema(description = "下达目标")
    private String releaseTargetName;

    @Column(name = "IS_AUTO_RELEASE_")
    @Schema(description = "是否自动下达")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private Integer isAutoRelease;

    @Column(name = "DIRECTOR_")
    @Schema(description = "部门/群组责任人")
    private String director;

    @Column(name = "PLAN_RELEASE_TIME_")
    @Schema(description = "计划下达时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date planReleaseTime;

    @Column(name = "DISPATCH_MODE_")
    @Schema(description = "派工模式")
    @Dict(dicCode = "ERP_EQUIPMENT_DISPATCH_MODE")
    private String dispatchMode;

    @Column(name = "ACTUAL_START_TIME_")
    @Schema(description = "实际开始时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date actualStartTime;

    @Column(name = "ACTUAL_END_TIME_")
    @Schema(description = "实际结束时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date actualEndTime;

    @Column(name = "IS_LAG_")
    @Schema(description = "滞后下达")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private Integer isLag;

    @Column(name = "LAG_TIME_")
    @Schema(description = "滞后下达时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lagTime;

    @Column(name = "EXECUTOR_")
    @Schema(description = "执行人")
    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    private String executor;

    @Column(name = "EQP_STATUS_")
    @Schema(description = "设备开关机状态")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private String eqpStatus;

    @Column(name = "RELEASE_TIME_")
    @Schema(description = "下达时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date releaseTime;

    @Column(name = "DISPATCH_TIME_")
    @Schema(description = "派工时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date dispatchTime;

    @Column(name = "DISPATCH_USER_")
    @Schema(description = "派工操作人")
    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    private String dispatchUser;

    @Column(name = "OVER_FLAG_")
    @Schema(description = "是否逾期（0-正常；1-逾期）")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private Integer overFlag;

    @Column(name = "WORK_MINUTES_")
    @Schema(description = "维修工时(分钟)")
    private Long workMinutes;

    @Transient
    private List<EquipmentUpkeepTaskDetail> upkeepTaskDetails;

    @Transient
    private String reason;

}
